package com.ruoyi.accounts.service.registry;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.accounts.service.IClientHandler;
import com.ruoyi.accounts.service.impl.TBJClientHandlerImpl;
import com.ruoyi.accounts.service.impl.WWJClientHandlerImpl;
import com.ruoyi.accounts.service.impl.CPJClientHandlerImpl;
import com.ruoyi.accounts.service.impl.DGJClientHandlerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;

@Component
public class ClientHandlerRegistry {
    private static final List<IClientHandler> handlers = new ArrayList<>();
    private static boolean initialized = false;
    
    @Autowired
    private WWJClientHandlerImpl wwjClientHandler;
    
    @Autowired
    private TBJClientHandlerImpl tbjClientHandler;
    
    @Autowired
    private CPJClientHandlerImpl cpjClientHandler;

    @Autowired
    private DGJClientHandlerImpl dgjClientHandler;

    @PostConstruct
    public void init() {
        if (!initialized) {
            handlers.add(wwjClientHandler);
            handlers.add(tbjClientHandler);
            handlers.add(cpjClientHandler);
            handlers.add(dgjClientHandler);
            initialized = true;
        }
    }
    
    // 根据机器类型查找处理器 1:娃娃机 2:推币机 3:彩票机 4:打怪机
    public static IClientHandler getHandler(Long machineType) {
        try {
            return handlers.stream()
                .filter(h -> h.getMachineType().equals(machineType))
                .findFirst()
                .orElse(null);
        } catch (Exception e) {
            return null;
        }
    }
}
